package com.doit.day05

import scala.io.Source

/**
 * 返回一个结果：order011  u001   300  hls  22   fengjie
 */
object JoinDemo {
  def main(args: Array[String]): Unit = {
    //怎么做 1.读取数据
    val user: List[String] = Source.fromFile("data/user.txt").getLines().toList
    val order: List[String] = Source.fromFile("data/order.txt").getLines().toList
    //你要做什么   要把一行数据进行切割后封装==》对象  元祖
    val userTuple: List[(String, String, String, String)] = user.map(line => {
      val arr: Array[String] = line.split(",")
      (arr(0), arr(1), arr(2), arr(3))
    })

    val orderTuple: List[(String, String, String)] = order.map(line => {
      val arr: Array[String] = line.split(",")
      (arr(0), arr(1), arr(2))
    })

    for (order <- orderTuple) {
      print((order._1,order._2,order._3))
      for (user <- userTuple) {
        if(user._1 == order._2){
          println((user._1,user._2,user._3,user._4))
        }
      }
    }

/*
    //2.接下来要干什么事儿类？  拼接
    //u009,wanghongjing,24,wife
    val map = userTuple.map(tp => {
      (tp._1, (tp._2, tp._3, tp._4))
    }).toMap
//    val map: Map[String, (String, String, String)] = tuples1.toMap



//    val userAndList: Map[String, List[(String, String, String, String)]] = userTuple.groupBy(_._1)

    for (elem <- orderTuple) {
      val user_id: String = elem._2
      val tuples: Option[(String, String, String)] = map.get(user_id)
      if(tuples.isDefined){
        val tp: (String, String, String) = tuples.get
        println((elem._1,user_id,elem._3,tp._1,tp._2,tp._3))
      }
    }*/





  }
}
